/*     */ package com.zimbra.cs.ldap.unboundid;
/*     */ 
/*     */ import com.unboundid.asn1.ASN1Element;
/*     */ import com.unboundid.asn1.ASN1Exception;
/*     */ import com.unboundid.asn1.ASN1Integer;
/*     */ import com.unboundid.asn1.ASN1OctetString;
/*     */ import com.unboundid.asn1.ASN1Sequence;
/*     */ import com.unboundid.ldap.sdk.Control;
/*     */ import com.unboundid.ldap.sdk.DecodeableControl;
/*     */ import com.unboundid.ldap.sdk.LDAPException;
/*     */ import com.unboundid.ldap.sdk.ResultCode;
/*     */ import com.unboundid.ldap.sdk.SearchResult;
/*     */ import com.unboundid.util.Debug;
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ public final class NoopSearchControl
/*     */   extends Control
/*     */   implements DecodeableControl
/*     */ {
/*     */   public static final String NOOP_SEARCH_OID = "1.3.6.1.4.1.4203.666.5.18";
/*     */   public static final String NOOP_CONTROL_NAME = "OpenLDAP No-op Search Control";
/*     */   private final long count;
/*     */   
/*     */   static enum ControlMessages
/*     */   {
/*  48 */     ERR_NOOP_SEARCH_NO_VALUE("No control value was provided, so it could not be decoded as a noop search response control."), 
/*  49 */     ERR_NOOP_SEARCH_NOT_SEQUENCE("Unable to decode the value of the provided control as an noop search control sequence:  %s"), 
/*  50 */     ERR_NOOP_SEARCH_INVALID_ELEMENT_COUNT("Unexpected number of elements in the noop search value sequence (expected 3, got %d)."), 
/*  51 */     ERR_NOOP_SEARCH_ELEMENT_NOT_INTEGER("Unable to decode the first element of the simple paged results value sequence as an integer: %s"), 
/*  52 */     ERR_NOOP_SEARCH_UNEXPECTED_SEARCH_RESULT_CODE("Unexpected search result code: [%s].");
/*     */     
/*     */     private final String defaultText;
/*     */     
/*     */     private ControlMessages(String defaultText)
/*     */     {
/*  58 */       this.defaultText = defaultText;
/*     */     }
/*     */     
/*     */     private String get() {
/*  62 */       return this.defaultText;
/*     */     }
/*     */     
/*     */     public String get(Object... args) {
/*  66 */       return String.format(get(), args);
/*     */     }
/*     */   }
/*     */   
/*     */   public NoopSearchControl()
/*     */   {
/*  72 */     super("1.3.6.1.4.1.4203.666.5.18", false);
/*  73 */     this.count = 0L;
/*     */   }
/*     */   
/*     */   public NoopSearchControl(String oid, boolean isCritical, ASN1OctetString value)
/*     */     throws LDAPException
/*     */   {
/*  79 */     super(oid, isCritical, value);
/*     */     
/*  81 */     if (value == null) {
/*  82 */       throw new LDAPException(ResultCode.DECODING_ERROR, ControlMessages.ERR_NOOP_SEARCH_NO_VALUE.get());
/*     */     }
/*     */     
/*     */     ASN1Sequence valueSequence;
/*     */     try
/*     */     {
/*  88 */       ASN1Element valueElement = ASN1Element.decode(value.getValue());
/*  89 */       valueSequence = ASN1Sequence.decodeAsSequence(valueElement);
/*     */     } catch (ASN1Exception ae) {
/*  91 */       Debug.debugException(ae);
/*  92 */       throw new LDAPException(ResultCode.DECODING_ERROR, ControlMessages.ERR_NOOP_SEARCH_NOT_SEQUENCE.get(new Object[] { ae }), ae);
/*     */     }
/*     */     
/*     */ 
/*  96 */     ASN1Element[] valueElements = valueSequence.elements();
/*  97 */     if (valueElements.length != 3) {
/*  98 */       throw new LDAPException(ResultCode.DECODING_ERROR, ControlMessages.ERR_NOOP_SEARCH_INVALID_ELEMENT_COUNT.get(new Object[] { Integer.valueOf(valueElements.length) }));
/*     */     }
/*     */     
/*     */     int searchResultCode;
/*     */     
/*     */     try
/*     */     {
/* 105 */       searchResultCode = ASN1Integer.decodeAsInteger(valueElements[0]).intValue();
/*     */     }
/*     */     catch (ASN1Exception ae) {
/* 108 */       Debug.debugException(ae);
/* 109 */       throw new LDAPException(ResultCode.DECODING_ERROR, ControlMessages.ERR_NOOP_SEARCH_ELEMENT_NOT_INTEGER.get(new Object[] { ae }), ae);
/*     */     }
/*     */     
/*     */ 
/* 113 */     if (searchResultCode != ResultCode.SUCCESS.intValue()) {
/* 114 */       ResultCode resultCode = ResultCode.valueOf(searchResultCode);
/* 115 */       throw new LDAPException(resultCode, ControlMessages.ERR_NOOP_SEARCH_UNEXPECTED_SEARCH_RESULT_CODE.get(new Object[] { resultCode.toString() }));
/*     */     }
/*     */     
/*     */     try
/*     */     {
/* 120 */       this.count = ASN1Integer.decodeAsInteger(valueElements[1]).intValue();
/*     */     } catch (ASN1Exception ae) {
/* 122 */       Debug.debugException(ae);
/* 123 */       throw new LDAPException(ResultCode.DECODING_ERROR, ControlMessages.ERR_NOOP_SEARCH_ELEMENT_NOT_INTEGER.get(new Object[] { ae }), ae);
/*     */     }
/*     */   }
/*     */   
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */   public String getControlName()
/*     */   {
/* 142 */     return "OpenLDAP No-op Search Control";
/*     */   }
/*     */   
/*     */   public static NoopSearchControl get(SearchResult result) throws LDAPException
/*     */   {
/* 147 */     Control c = result.getResponseControl("1.3.6.1.4.1.4203.666.5.18");
/* 148 */     if (c == null) {
/* 149 */       return null;
/*     */     }
/*     */     
/* 152 */     if ((c instanceof NoopSearchControl)) {
/* 153 */       return (NoopSearchControl)c;
/*     */     }
/* 155 */     return new NoopSearchControl(c.getOID(), c.isCritical(), c.getValue());
/*     */   }
/*     */   
/*     */ 
/*     */   public NoopSearchControl decodeControl(String oid, boolean isCritical, ASN1OctetString value)
/*     */     throws LDAPException
/*     */   {
/* 162 */     return new NoopSearchControl(oid, isCritical, value);
/*     */   }
/*     */   
/*     */   public long getCount() {
/* 166 */     return this.count;
/*     */   }
/*     */ }


/* Location:              /home/mint/zimbrastore.jar!/com/zimbra/cs/ldap/unboundid/NoopSearchControl.class
 * Java compiler version: 7 (51.0)
 * JD-Core Version:       0.7.1
 */